
public class countingSort {
	
	static int getMax(int[] a){
		if(a == null || a.length == 0)
			return -1;
		int max = a[0];
		for (int i=1; i<a.length; i++){
			if (a[i] > max){
				max = a[i];
			}
		}
		return max;
	}
	
	public static void main(String[] args) {

		int a[] = {1, 5, 5, 3, 8, 2, 3, 2, 1, 5, 8};
		int sizea = a.length;
		int sizeb = getMax(a) + 1;
		int b[] = new int[sizeb];
		int[] result = new int[sizea];
		
		for (int j = 0; j<sizea; j++){
			int value = a[j];
			b[value]++;
		}
		
		b[0]--;
		for (int j = 1; j<sizeb; j++){
			b[j] += b[j-1];
			
			System.out.print(b[j] + " ");
		}
		

		
//		int k = 0;
//		for(int i = 0; i < sizeb; i++){
//			for(int j = 0; j < b[i]; j++){
//				a[k++] = i;
//				System.out.print(a[k-1]+ " ");
//			}
//		}
		
		
		
	
	
	}
}
